/**
 * Copyright &copy; 2012-2014 ThinkGem All rights reserved.
 */
package com.sx.admin.shiro;

import com.sx.core.model.Operator;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

/**
 * 用户工具类
 */
public class SecurityUserUtils {

	/**
	 * 获取授权主要对象
	 */
	public static Subject getSubject(){
		return SecurityUtils.getSubject();
	}

	/**
	 * 获取当前登录者对象
	 */
	public static AdminPrincipal getPrincipal(){
		Subject subject = SecurityUtils.getSubject();
		AdminPrincipal principal = (AdminPrincipal)subject.getPrincipal();
		if (principal != null){
			return principal;
		}
		return null;
	}

	public static Session getSession(){
		Subject subject = SecurityUtils.getSubject();
		Session session = subject.getSession(false);
		if (session == null){
			session = subject.getSession();
		}
		return session;
	}
	public static void setSessionAttribute(String name, Object value){
		getSession().setAttribute(name,value);
	}
	public static Object getSessionAttribute(String name){
		return getSession().getAttribute(name);
	}

	public static Operator getOperator(){
		AdminPrincipal principal=getPrincipal();
		return principal!=null?principal.getOperator():null;
	}
	public static boolean isValidateCodeLogin(String useruame, boolean isFail, boolean clean){

		return false;
	}

}
